package com.ruoyi.ammunition.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ammunition.domain.Ammunition;
import com.ruoyi.ammunition.service.IAmmunitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 弹药，存储弹药的基本信息Controller
 * 
 * @author guo
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/ammunition/ammunition")
public class AmmunitionController extends BaseController
{
    @Autowired
    private IAmmunitionService ammunitionService;

    /**
     * 查询弹药，存储弹药的基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:list')")
    @GetMapping("/list")
    public TableDataInfo list(Ammunition ammunition)
    {
        startPage();
        List<Ammunition> list = ammunitionService.selectAmmunitionList(ammunition);
        return getDataTable(list);
    }

    /**
     * 导出弹药，存储弹药的基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:export')")
    @Log(title = "弹药，存储弹药的基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ammunition ammunition)
    {
        List<Ammunition> list = ammunitionService.selectAmmunitionList(ammunition);
        ExcelUtil<Ammunition> util = new ExcelUtil<Ammunition>(Ammunition.class);
        util.exportExcel(response, list, "弹药，存储弹药的基本信息数据");
    }

    /**
     * 获取弹药，存储弹药的基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ammunitionService.selectAmmunitionById(id));
    }

    /**
     * 新增弹药，存储弹药的基本信息
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:add')")
    @Log(title = "弹药，存储弹药的基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ammunition ammunition)
    {
        return toAjax(ammunitionService.insertAmmunition(ammunition));
    }

    /**
     * 修改弹药，存储弹药的基本信息
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:edit')")
    @Log(title = "弹药，存储弹药的基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ammunition ammunition)
    {
        return toAjax(ammunitionService.updateAmmunition(ammunition));
    }

    /**
     * 删除弹药，存储弹药的基本信息
     */
    @PreAuthorize("@ss.hasPermi('ammunition:ammunition:remove')")
    @Log(title = "弹药，存储弹药的基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ammunitionService.deleteAmmunitionByIds(ids));
    }
}
